package org.micode.demo.web.service;

import lombok.extern.slf4j.Slf4j;
import org.micode.common.domain.DataPage;
import org.micode.common.domain.vo.KeyVO;
import org.micode.common.helper.MethodHelper;
import org.micode.demo.biz.service.BizSysDictionaryService;
import org.micode.demo.db.domain.dto.SysDictionaryDTO;
import org.micode.demo.db.domain.query.SysDictionaryQuery;
import org.micode.demo.db.service.DaoSysDictionaryService;
import org.micode.demo.db.vo.IdNameVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 字典配置信息(sys_dictionary) 的APP服务实现类
 *
 * @author: wutianbin
 * @version: v1.0.24
 * @CreateDate: 2021-09-06
 */
@Service
@Slf4j
public class SysDictionaryService {

    @Autowired
    private DaoSysDictionaryService daoSysDictionaryService;

    @Autowired
    private BizSysDictionaryService bizSysDictionaryService;

    public DataPage<SysDictionaryDTO> list(SysDictionaryQuery dataQuery) {
        return MethodHelper.invoke(daoSysDictionaryService::listPage, dataQuery);
    }

    public SysDictionaryDTO info(KeyVO<Long> id) {
        return MethodHelper.invoke(daoSysDictionaryService::get, id.getKey());
    }

    public List<IdNameVO> listIdName(String paramType) {
        List<SysDictionaryDTO> list = bizSysDictionaryService.listByType(paramType);
        if (null != list) {
            List<IdNameVO> ret = new ArrayList<>();
            list.forEach(item -> {
                IdNameVO vo = new IdNameVO();
                vo.setId(item.getParamValue());
                vo.setName(item.getParamName());
                ret.add(vo);
            });
            return ret;
        }
        return null;
    }

    public List<SysDictionaryDTO> listByParamType(String paramType) {
        return bizSysDictionaryService.listByType(paramType);
    }

}
